﻿package mortal.game.view.flowerSend.panel
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.flowerSend.data.*;
    import mortal.mvc.core.*;

    public class FlowerSendingBox extends GSprite
    {
        private var _nameList:GComboBox;
        private var _flowerNumList:GComboBox;
        private var _signature:GRadioButton;
        private var _anonymous:GRadioButton;
        private var _autoBuy:GCheckBox;
        private var _sendBtn:GLoadingButton;
        private var _flowerIcon:GImageBitmap;
        private var _isAutoBuy:Boolean = false;
        protected var _data:FlowerSendData;
        public static const flowerBaseCode:int = 300000000;

        public function FlowerSendingBox()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.FlowerTxt_5, 0, 0, this));
            this._signature = UIFactory.radioButton(Language.getString(35294), 3, 52, 100, 28, this, "GRadioButton");
            this._anonymous = UIFactory.radioButton(Language.getString(35295), 80, 52, 100, 28, this, "GRadioButton");
            this._signature.groupName = "FlowerSend";
            this._anonymous.groupName = "FlowerSend";
            this._signature.selected = true;
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._nameList = UIFactory.gComboBox(3, 30, 160, 22, null, this);
            this._nameList.editable = true;
            this._nameList.configEventListener(Event.CHANGE, this.fowerChangeHandler);
            this._flowerNumList = UIFactory.gComboBox(3, 90, 160, 22, null, this);
            this._flowerNumList.configEventListener(Event.CHANGE, this.fowerChangeHandler);
            this._flowerNumList.editable = false;
            this._autoBuy = UIFactory.checkBox(Language.getString(30313), 3, 110, 210, 28, this);
            this._autoBuy.selected = this._isAutoBuy;
            this._autoBuy.configEventListener(Event.CHANGE, this.selectedChangeHandler);
            this._sendBtn = UIFactory.gLoadingButton(ResFileConst.FlowerSendBtn, 70, 150, 84, 73, this);
            this._sendBtn.drawNow();
            this._sendBtn.configEventListener(MouseEvent.CLICK, this.sendFlower);
            this._flowerIcon = UIFactory.gImageBitmap("", -65, 195, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._nameList.dispose(param1);
            this._nameList = null;
            this._signature.dispose(param1);
            this._signature = null;
            this._anonymous.dispose(param1);
            this._anonymous = null;
            this._flowerNumList.dispose(param1);
            this._flowerNumList = null;
            this._autoBuy.dispose(param1);
            this._autoBuy = null;
            this._sendBtn.dispose(param1);
            this._sendBtn = null;
            this._flowerIcon.dispose(param1);
            this._flowerIcon = null;
            this._data = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function fowerChangeHandler(event:Event) : void
        {
            if (this.isDisposed)
            {
                return;
            }
            var _loc_2:* = this._flowerNumList.selectedItem.info as ItemInfo;
            this._flowerIcon.imgUrl = "FlowerType_" + _loc_2.type + "_" + _loc_2.itemLevel;
            return;
        }// end function

        private function sendFlower(event:MouseEvent) : void
        {
            if (this._nameList.selectedIndex >= 0)
            {
                this._data.toPlayer = this._nameList.selectedItem["info"] as SMiniPlayer;
            }
            else if (this._nameList.text)
            {
                this._data.toPlayer = new SMiniPlayer();
                this._data.toPlayer.name = this._nameList.text;
            }
            else
            {
                return MsgManager.showRollTipsMsg(Language.getString(35296));
            }
            if (this._data.toPlayer.name == Cache.instance.role.entityInfo.name)
            {
                return MsgManager.showRollTipsMsg(Language.getString(35297));
            }
            this._data.autoBuy = this._autoBuy.selected;
            this._data.itemData = new ItemData((this._flowerNumList.selectedItem["info"] as ItemInfo).code);
            this._data.anonymous = this._anonymous.selected;
            Dispatcher.dispatchEvent(new DataEvent(EventName.FlowerSend, this._data));
            return;
        }// end function

        private function selectedChangeHandler(event:Event) : void
        {
            this._isAutoBuy = this._autoBuy.selected;
            return;
        }// end function

        protected function updateFriendList() : void
        {
            var _loc_2:SFriendRecord = null;
            var _loc_4:int = 0;
            var _loc_1:* = Cache.instance.friend.friendList;
            var _loc_3:int = -1;
            while (_loc_4 < _loc_1.length)
            {
                
                _loc_2 = _loc_1[_loc_4];
                if (_loc_2 && _loc_2.friendPlayer.online)
                {
                    if (this._data.toPlayer && this._data.toPlayer.name == _loc_2.friendPlayer.name)
                    {
                        _loc_3 = _loc_4;
                    }
                    this._nameList.addItem({label:_loc_2.friendPlayer.name, info:_loc_2.friendPlayer});
                }
                _loc_4++;
            }
            if (this._data && this._data.toPlayer)
            {
                this._nameList.selectedIndex = -1;
                this._nameList.text = this._data.toPlayer.name;
            }
            else
            {
                this._nameList.selectedIndex = _loc_3;
            }
            return;
        }// end function

        protected function updateFlowerList() : void
        {
            var _loc_3:ItemInfo = null;
            this._flowerNumList.removeAll();
            var _loc_1:* = flowerBaseCode;
            if (ItemsUtil.isBind(this._data.itemData))
            {
                _loc_1 = _loc_1 + 1000;
            }
            var _loc_2:* = _loc_1 + 100;
            var _loc_4:int = -1;
            var _loc_5:* = _loc_1;
            while (_loc_5 < _loc_2)
            {
                
                _loc_3 = ItemConfig.instance.getConfig(_loc_5);
                if (_loc_3 && this._data.itemData && _loc_3.type == this._data.itemData.itemInfo.type)
                {
                    this._flowerNumList.addItem({label:_loc_3.name, info:_loc_3});
                    if (this._data.itemData && this._data.itemData.itemCode == _loc_3.code)
                    {
                        _loc_4 = this._flowerNumList.dataProvider.length - 1;
                    }
                }
                _loc_5++;
            }
            this._flowerNumList.selectedIndex = _loc_4;
            return;
        }// end function

        public function set data(param1:FlowerSendData) : void
        {
            this._data = param1;
            this._flowerIcon.imgUrl = "FlowerType_" + this._data.itemData.itemInfo.type + "_" + this._data.itemData.itemInfo.itemLevel;
            this.updateFriendList();
            this.updateFlowerList();
            return;
        }// end function

    }
}
